﻿using System;
using System.Configuration;
using System.Messaging;

namespace JCE.ARB
{
	public static class GlobalState
	{
		public static bool IsRunning { get; set; }
		public static bool HasStopped { get; set; }
		public static bool IsPaused { get; set; }
		public static string InstanceName { get; private set; }
		public static string MessageQueuePath { get; private set; }
		public static MessageQueue ARBQueue { get; private set; }
		public static IMessageFormatter ARBQueueFormatter { get; private set; }

		static GlobalState()
		{
			InstanceName = ConfigurationManager.AppSettings["InstanceName"] ?? "DEFAULT";
			MessageQueuePath = string.Format(LocalizedStrings.MessageQueuePath, InstanceName);
			if (MessageQueue.Exists(MessageQueuePath))
			{
				ARBQueue = new MessageQueue(MessageQueuePath);
			}
			else
			{
				ARBQueue = MessageQueue.Create(MessageQueuePath);
			}
			ARBQueueFormatter = new BinaryMessageFormatter();
		}
	}
}
